home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c.moderated,comp.lang.c
- Subject: Re: fflush(stdin) - not guaranteed to work?
- Followup-To: comp.lang.c.moderated,comp.lang.c
- Date: 15 Apr 1996 13:08:03 -0500
- Organization: TRIUMF: Tri-University Meson Facility
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4ku3a3$4u9@solutions.solon.com>
- References: <4ksjpn$rjt@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4ksjpn$rjt@solutions.solon.com>, gohel@csee.usf.edu writes...
- >In Paul S. Wang's "Introduction to ANSI C on UNIX" he says that
- >the fflush() function was "not intended to control input buffering"
- >on page 266.
-
- I believe the C standard agrees with him. :-)
-
- >What is the best way to get rid of the '\n' from the input buffer after
- >a scanf() statement? In the same book on page 263 I've seen the following
- >format used in an fscanf() format specifier:
-
- don't use scanf() for direct user input - besides the "leftover '\n'" problem,
- it can cause great grief if the user enters a letter when scanf() is expecting
- a number.
-
- A better input procedure is to get a line with fgets(), then parse it with
- sscanf(), strtok(), or other functions.
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
-